<template>
    <div id="app">
      <el-form :model="studentWorkhome" label-width="100px"  ref="abc">
        <el-form-item label="作业题目" prop="lid">
          <el-select v-model="studentWorkhome.wid" placeholder="请选择">
            <el-option
              v-for="item in workhomeList"
              :key="item.id"
              :label="item.title"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="作业附件" prop="content">
          <el-upload
            class="upload-demo"
            action="http://localhost:8989/studentWorkhome/uploadAttach"
            :limit="1"
            :on-exceed="handleOnExceed"
            name="attach"
            accept=".pdf"
            :multiple="false"
            :on-success="handleOnSuccess"
          >
            <el-button size="small" type="primary">点击上传</el-button>
            <div slot="tip" class="el-upload__tip">只能上传pdf文件</div>
          </el-upload>
        </el-form-item>

        <el-form-item label="作业描述" prop="description">
          <el-input v-model="studentWorkhome.studentDescription"  type="textarea" rows="5"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click.prevent="test">保存</el-button>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
    export default {
      data(){
        return {
          studentWorkhome:{},
          workhomeList:[]
        }
      },
      created() {
        this.axios.get("/workhome/selectAll").then((resp)=>{
          this.workhomeList=resp.data;
        });
      },
      methods:{
        test(){
            this.$confirm("是否确认提交","保存提示").then(()=>{
              this.axios.post("/studentWorkhome/add",this.studentWorkhome).then((resp)=>{
                  this.$message.success("保存成功！");
                });
            }).catch(()=>{});
        },
        handleOnExceed(){
          console.log("文件个数超出限制");
        },
        handleOnSuccess(resp){
          //文件上传成功之后要把文件上传到哪传给brand对象
          this.studentWorkhome.attachment=resp;
        },
      }
    }
</script>


<style scoped>

</style>
